#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int T,n,m,L,V;
int p[N],d[N],v[N],a[N],leave[N],ans1[N],ans2[N];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    for(int x=1;x<=T;x++){
        cin>>n>>m>>L>>V;
        leave[N]={0};
        for(int i=1;i<=n;i++)
            cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++)
            cin>>p[i];
        for(int i=1;i<=n;i++)
                if(a[i]==0)
                    if(v[i]>V){
                        ans1[x]++;
                        for(int j=1;j<=m;j++)
                            if(p[j]>=d[i])
                                for(int y=j+1;y<=m;y++) leave[y]=1;
                    }
        for(int i=1;i<=m;i++)
            if(leave[i]==1) ans2[x]++;
    }
    for(int x=1;x<=T;x++)
        cout<<ans1[x]<<" "<<ans2[x]<<endl;
    return 0;
}
